#region Copyright RenGuiYou. All rights reserved.
//=====================================================
// NeatlyFrameWork
// Author:      RenGuiyou
// Feedback: 	mailto:750539605@qq.com
//=====================================================
#endregion
using UnityEngine;

public static class PlayerPrefsHelper
{
    public const int FALSE = 0;
    public const int TRUE = 1;
    public const string KEY_MUSIC_VOLUME = "KEY_MUSIC_VOLUME";
    public const string KEY_SOUND_VOLUME = "KEY_SOUND_VOLUME";
    public const string KEY_VOICE_VOLUME = "KEY_VOICE_VOLUME";
    public const string KEY_MUSIC_MUTE = "KEY_MUSIC_MUTE";
    public const string KEY_SOUND_MUTE = "KEY_SOUND_MUTE";
    public const string KEY_VOICE_MUTE = "KEY_VOICE_MUTE";
    public const string KEY_LANGUAGE = "KEY_LANGUAGE";
    #region main function
    public static float GetFloat(string key, float defaultVal = 0)
    {
        if (NeatlyAction.WXGetFloatPrefsFunc != null)
        {
            return NeatlyAction.WXGetFloatPrefsFunc(key, defaultVal);
        }
        else
        {
            return PlayerPrefs.GetFloat(key, defaultVal);
        }
    }

    public static void SetFloat(string key, float value)
    {
        if (NeatlyAction.WXSetFloatPrefsFunc != null)
        {
            NeatlyAction.WXSetFloatPrefsFunc(key, value);
        }
        else
        {
            PlayerPrefs.SetFloat(key, value);
        }
    }

    public static int GetInt(string key, int defaultVal = 0)
    {
        if (NeatlyAction.WXGetIntPrefsFunc != null)
        {
            return NeatlyAction.WXGetIntPrefsFunc(key, defaultVal);
        }
        else
        {
            return PlayerPrefs.GetInt(key, defaultVal);
        }
    }

    public static void SetInt(string key, int value)
    {
        if (NeatlyAction.WXSetIntPrefsFunc != null)
        {
            NeatlyAction.WXSetIntPrefsFunc(key, value);
        }
        else
        {
            PlayerPrefs.SetInt(key, value);
        }
    }

    public static string GetString(string key, string defaultVal = "")
    {
        if (NeatlyAction.WXGetStringPrefsFunc != null)
        {
            return NeatlyAction.WXGetStringPrefsFunc(key, defaultVal);
        }
        else
        {
            return PlayerPrefs.GetString(key, defaultVal);
        }
    }

    public static void SetString(string key, string value)
    {
        if (NeatlyAction.WXSetStringPrefsFunc != null)
        {
            NeatlyAction.WXSetStringPrefsFunc(key, value);
        }
        else
        {
            PlayerPrefs.SetString(key, value);
        }
    }

    public static bool GetBool(string key, bool defaultVal = false)
    {
        int value = defaultVal ? TRUE : FALSE;
        if (NeatlyAction.WXGetIntPrefsFunc != null)
        {
            return NeatlyAction.WXGetIntPrefsFunc(key, value) == TRUE;
        }
        else
        {
            return PlayerPrefs.GetInt(key, value) == TRUE;
        }
    }

    public static void SetBool(string key, bool value)
    {
        int rValue = value ? TRUE : FALSE;
        if (NeatlyAction.WXSetIntPrefsFunc != null)
        {
            NeatlyAction.WXSetIntPrefsFunc(key, rValue);
        }
        else
        {
            PlayerPrefs.SetInt(key, rValue);
        }
    }

    public static void Save()
    {
        PlayerPrefs.Save();
    }
    #endregion

    //音乐音量
    public static float GetMusicVolume(float defaultVal = 1)
    {
        return GetFloat(KEY_MUSIC_VOLUME, defaultVal);
    }

    public static void SetMusicVolume(float val)
    {
        SetFloat(KEY_MUSIC_VOLUME, val);
    }

    //音乐静音
    public static bool GetMusicMute(bool defaultVal = false)
    {
        return GetBool(KEY_MUSIC_MUTE, defaultVal);
    }

    public static void SetMusicMute(bool val)
    {
        SetBool(KEY_MUSIC_MUTE, val);
    }

    //音效音量
    public static float GetSoundVolume(float defaultVal = 1)
    {
        return GetFloat(KEY_SOUND_VOLUME, defaultVal);
    }

    public static void SetSoundVolume(float val)
    {
        SetFloat(KEY_SOUND_VOLUME, val);
    }

    //音效静音
    public static bool GetSoundMute(bool defaultVal = false)
    {
        return GetBool(KEY_SOUND_MUTE, defaultVal);
    }

    public static void SetSoundMute(bool val)
    {
        SetBool(KEY_SOUND_MUTE, val);
    }

    //Voice音量
    public static float GetVoiceVolume(float defaultVal = 1)
    {
        return GetFloat(KEY_VOICE_VOLUME, defaultVal);
    }

    public static void SetVoiceVolume(float val)
    {
        SetFloat(KEY_VOICE_VOLUME, val);
    }

    //Voice静音
    public static bool GetVoiceMute(bool defaultVal = false)
    {
        return GetBool(KEY_VOICE_MUTE, defaultVal);
    }

    public static void SetVoiceMute(bool val)
    {
        SetBool(KEY_VOICE_MUTE, val);
    }

    //多语言
    public static string GetLanguage(string val)
    {
        return GetString(KEY_LANGUAGE, val);
    }

    public static void SetLanguage(string val)
    {
        SetString(KEY_LANGUAGE, val);
    }
}